﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;

namespace dogd.Tests.Fakes
{
	public class FakeDbCommand : DbCommand
	{
		private DbParameterCollection _parameters;

		public FakeDbCommand()
		{
			this._parameters = new FakeDbParameterCollection();
		}

		public override void Cancel()
		{
		}

		public override string CommandText
		{
			get;
			set;
		}

		public override int CommandTimeout
		{
			get;
			set;
		}

		public override System.Data.CommandType CommandType
		{
			get;
			set;
		}

		protected override DbParameter CreateDbParameter()
		{
			return new FakeDbParameter();
		}

		protected override DbConnection DbConnection
		{
			get;
			set;
		}

		protected override DbParameterCollection DbParameterCollection
		{
			get { return this._parameters; }
		}

		protected override DbTransaction DbTransaction
		{
			get;
			set;
		}

		public override bool DesignTimeVisible
		{
			get;
			set;
		}

		protected override DbDataReader ExecuteDbDataReader(System.Data.CommandBehavior behavior)
		{
			throw new NotImplementedException();
		}

		public override int ExecuteNonQuery()
		{
			throw new NotImplementedException();
		}

		public override object ExecuteScalar()
		{
			throw new NotImplementedException();
		}

		public override void Prepare()
		{
		}

		public override System.Data.UpdateRowSource UpdatedRowSource
		{
			get;
			set;
		}
	}

	public class FakeDbParameter : DbParameter
	{
		public override System.Data.DbType DbType
		{
			get;
			set;
		}

		public override System.Data.ParameterDirection Direction
		{
			get;
			set;
		}

		public override bool IsNullable
		{
			get;
			set;
		}

		public override string ParameterName
		{
			get;
			set;
		}

		public override void ResetDbType()
		{
		}

		public override int Size
		{
			get;
			set;
		}

		public override string SourceColumn
		{
			get;
			set;
		}

		public override bool SourceColumnNullMapping
		{
			get;
			set;
		}

		public override System.Data.DataRowVersion SourceVersion
		{
			get;
			set;
		}

		public override object Value
		{
			get;
			set;
		}
	}

	public class FakeDbParameterCollection : DbParameterCollection
	{
		private List<DbParameter> _items;

		public FakeDbParameterCollection()
		{
			this._items = new List<DbParameter>();
		}

		public override int Add(object value)
		{
			var item = value as FakeDbParameter;

			if (item != null)
			{
				this._items.Add(item);
			}

			return this._items.Count - 1;
		}

		public override void AddRange(Array values)
		{
			throw new NotImplementedException();
		}

		public override void Clear()
		{
			this._items.Clear();
		}

		public override bool Contains(string value)
		{
			throw new NotImplementedException();
		}

		public override bool Contains(object value)
		{
			throw new NotImplementedException();
		}

		public override void CopyTo(Array array, int index)
		{
			throw new NotImplementedException();
		}

		public override int Count
		{
			get { return _items.Count; }
		}

		public override System.Collections.IEnumerator GetEnumerator()
		{
			return _items.GetEnumerator();
		}

		protected override DbParameter GetParameter(string parameterName)
		{
			throw new NotImplementedException();
		}

		protected override DbParameter GetParameter(int index)
		{
			return _items[index];
		}

		public override int IndexOf(string parameterName)
		{
			throw new NotImplementedException();
		}

		public override int IndexOf(object value)
		{
			throw new NotImplementedException();
		}

		public override void Insert(int index, object value)
		{
			throw new NotImplementedException();
		}

		public override bool IsFixedSize
		{
			get { throw new NotImplementedException(); }
		}

		public override bool IsReadOnly
		{
			get { throw new NotImplementedException(); }
		}

		public override bool IsSynchronized
		{
			get { throw new NotImplementedException(); }
		}

		public override void Remove(object value)
		{
			throw new NotImplementedException();
		}

		public override void RemoveAt(string parameterName)
		{
			throw new NotImplementedException();
		}

		public override void RemoveAt(int index)
		{
			throw new NotImplementedException();
		}

		protected override void SetParameter(string parameterName, DbParameter value)
		{
			throw new NotImplementedException();
		}

		protected override void SetParameter(int index, DbParameter value)
		{
			throw new NotImplementedException();
		}

		public override object SyncRoot
		{
			get { throw new NotImplementedException(); }
		}
	}

	public class FakeParameterFactory : IParameterFactory
	{
		public DbParameter CreateReadParameter(Key key, ColumnMetadata metadata)
		{
			return new FakeDbParameter()
				{
					DbType = System.Data.DbType.Int32,
					ParameterName = metadata.Parameter,
					Value = key.Value
				};
		}

		public DbParameter CreateReadParameter(string id, ColumnMetadata metadata)
		{
			return new FakeDbParameter()
			{
					DbType = System.Data.DbType.String,
					ParameterName = metadata.Parameter,
					Value = id
				};
		}

		public DbParameter CreateWriteParameter(object value, ColumnMetadata metadata)
		{
			return new FakeDbParameter();
		}
	}
}
